package com.pansoft.openplanet.util;

import com.utilcode.util.EncryptUtils;

import java.util.Map;

/**
 * 重置fgt 接口参数加密
 *
 * @autor yqs
 * @date 2018/10/23 14:43
 **/
public class TcRechargeEncryptUtl {
    private static final String appId = "2";
    private static final String appKey = "d80173c2-dd26-4e5a-a352-97fb238d1154";
    private static final String appSecret = "B55FB310A2F66C6D51BBBB4BEFE9914A6E1D1F3B";


    /**
     * 设置加密参数
     *
     * @param paramMap
     */
    public static void setEnceptParam(Map<String, String> paramMap) {
        long timestamp = System.currentTimeMillis();
        String nonce = getSixRandom();
        String original = appId + appKey + timestamp + nonce + appSecret;
        String signature = EncryptUtils.encryptSHA1ToString(original).toUpperCase();

        paramMap.put("appId", appId);
        paramMap.put("appKey", appKey);
        paramMap.put("appId", appId);
        paramMap.put("timestamp", timestamp + "");
        paramMap.put("nonce", nonce);
        paramMap.put("signature", signature);
    }

    /**
     * 获取6位随机数
     *
     * @return
     */
    private static String getSixRandom() {
        int random = (int) ((Math.random() * 9 + 1) * 100000);
        return random + "";
    }

    public static void main(String[] args) {

        long timestamp = System.currentTimeMillis();

        String nonce = getSixRandom();
        String original = appId + appKey + timestamp + nonce + appSecret;
        String signature = EncryptUtils.encryptSHA1ToString(original).toUpperCase();

        System.out.println(timestamp + "");
        System.out.println(nonce + "");
        System.out.println(original + "");
        System.out.println(signature + "");

    }
}
